import Vue from 'vue'
import Router from 'vue-router'
import HelloWorld from '@/components/HelloWorld'
import mint from '@/components/class2/mint-ui'
import todo from '@/components/class1/todo'
import class2Router from '@/components/class2/0420router'
import class2 from '@/components/class2/class2'
import cdh from '@/components/class2/cdh'
import fhy from '@/components/class2/fhy'
import class1Router from '@/components/class1/0420router'
import promise from '@/components/class1/promise'
import error from '@/components/class2/0420-404'
import dashboard2 from '@/components/class2/dashboard'
import detail2 from '@/components/class2/detail'
import subDetail from '@/components/class2/detail2'
import joke2 from '@/components/class2/joke'
import dashboard1 from '@/components/class1/dashboard'
import detail1 from '@/components/class1/detail'

Vue.use(Router)

export default new Router({
  routes: [
    {
      path: '/error',
      name: 'error',
      component: error
    },
    {
      path: '/',
      name: 'HelloWorld',
      component: HelloWorld
    },
    {
      path: '/mint',
      name: 'mint',
      component: mint
    },
    {
      path: '/todo',
      name: 'todo',
      component: todo
    },
    {
      path: '/class2-router/:sku/about/:id',
      name: 'class2Router',
      component: class2Router,
      // 修改元信息
      meta: {
        title: 'class 2'
      },
      beforeEnter: (to, from, next) => {
        document.title = to.meta.title
        if (localStorage.getItem('name') != 'hxb') {
          alert('禁止进入！')
        }
        next()
      }
    },
    {
      path: '/class2',
      name: 'class2',
      component: class2,
      children: [
        {
          path: 'cdh',
          name: 'cdh',
          component: cdh
        },
        {
          path: 'fhy',
          name: 'fhy',
          component: fhy
        }
      ]
    },
    {
      path: '/dashboard2',
      name: 'dashboard2',
      component: dashboard2
    },
    {
      path: '/detail2/:sid',
      name: 'detail2',
      component: detail2
    },
    {
      path: '/joke2',
      name: 'joke2',
      component: joke2,
      children: [
        {
          path: ':sid',
          name: 'detail2',
          component: subDetail
        }
      ]
    },
    {
      path: '/class1-promise',
      name: 'promise',
      component: promise
    },
    {
      path: '/dashboard1',
      name: 'dashboard1',
      component: dashboard1
    },
    {
      path: '/detail1/:sid',
      name: 'detail1',
      component: detail1
    },
    {
      path: '*',
      redirect: '/error'
    }
  ]
})
